;--------------------------------------
;
; prog6-1.asm
;
; Demonstration of mouse & keybooard
; handler program
;   
;

;--------------------------------------
;
; include all defines, macros, 
; prototypes and set up memory model
;

include tab6.inc


;--------------------------------------
;
; Create stack
;
	.STACK                         ; 1 k by default

;--------------------------------------
;
; Declare data segment
;

	.DATA

scan_c  db      ?,0
char_c  db      ?,0
char_a  db      'Character:    ',0
scan_a  db      'Scan Code:   h',0
x_loc   dw      ?
y_loc   dw      ?
b32     db      32,0
buffer  db      12 DUP(0)
hbuff   db      12 DUP(0)
l_press db      'Left Button Press   ',0
r_press db      'Right Button Press and Program returned '
        db      'to DOS.',0
f_press db      'F10 Function Key Press and Program returned '
        db      'to DOS.',0
n_press db      '                    ',0
x_mess  db      'Mouse Row Position    =      ',0
y_mess  db      'Mouse Column Position =      ',0

;--------------------------------------
;
; Begin code segment
;

	.CODE


;--------------------------------------
;
; Start program here
;

	.STARTUP


; clear the screen

        INVOKE  clrScrn,7
        INVOKE  offCur
        INVOKE  bdwrite,0,0,ADDR y_mess
        INVOKE  bdwrite,1,0,ADDR x_mess
        INVOKE  bdwrite,0,39,ADDR char_a
        INVOKE  bdwrite,1,39,ADDR scan_a

        INVOKE  msInit
        INVOKE  msOn

        .WHILE 1


        INVOKE  msStat, ADDR x_loc, ADDR y_loc
        .IF (ax == 2)
        .BREAK
        .ELSEIF (ax  == 1)
        INVOKE  bdwrite,2,0,ADDR l_press
        .ELSE
        INVOKE  bdwrite,2,0,ADDR n_press
        .ENDIF

        INVOKE  kbStat
        .IF ( ax == F10 )
        jmp     F10_press
        .ELSEIF ( ax != 0 )
        mov     char_c,al
        mov     scan_c,ah
        .IF ( char_c != 0 )
        INVOKE  bdwrite,0,50,ADDR char_c
        .ELSE
        INVOKE  bdwrite,0,50,ADDR b32
        .ENDIF
        INVOKE  itoh,ADDR hbuff,scan_c,HEX_8_BIT
        INVOKE  bdwrite,1,50,ADDR hbuff

        
        .ENDIF
        
        shr     x_loc,1
        shr     x_loc,1
        shr     x_loc,1
        shr     y_loc,1
        shr     y_loc,1
        shr     y_loc,1

        INVOKE  itoa,ADDR buffer,x_loc
        INVOKE  bdwrite,0,25,ADDR b32
        INVOKE  bdwrite,0,24,ADDR buffer
        INVOKE  itoa,ADDR buffer,y_loc
        INVOKE  bdwrite,1,25,ADDR b32
        INVOKE  bdwrite,1,24,ADDR buffer

        .ENDW

        INVOKE  bdwrite,2,0,ADDR r_press
        jmp     all_done

F10_press:

        INVOKE  bdwrite,2,0,ADDR f_press

all_done:

        INVOKE  msOff
        INVOKE  onCur



; move the cursor to 3,0

        INVOKE  mvCur,3,0



;
	.EXIT

;--------------------------------------
;
; End of ASSEMBLY source file
;

	END


;
;--------------------------------------
